import React, { FC, useContext } from 'react';
import { View, Text } from '@tarojs/components';
import { styled } from 'linaria/react';
import { useClassName } from '@/utils/index';
import { LoginFormContext } from '../LoginFormContext';
import MyInput from '../MyInput/MyInput';

export interface IProps extends ICompProps {}
PhoneNumber.defaultProps = {} as Partial<IProps>;
function PhoneNumber(props: IProps) {
    const { className, style } = props;
    const localClassName = useClassName('PhoneNumber', className);
    const { loginForm, valChange, validateTips, validatePhone } = useContext(LoginFormContext);
    return (
        <RootView className={localClassName} style={style}>
            <View className="phoneandTipsWrap">
                <MyInput
                    value={loginForm.phone}
                    onChange={(e) => valChange('phone', e)}
                    onBlur={(e) => validatePhone(e)}
                    placeholder="请输入手机号"
                    maxLength={11}
                    type="number"></MyInput>
                <Text className="tips" style={{ display: validateTips ? 'block' : 'none' }}>
                    {validateTips}
                </Text>
            </View>
        </RootView>
    );
}
export default React.memo(PhoneNumber as FC<IProps>);
const RootView = styled(View)`
    &.PhoneNumber {
        position: relative;
        margin-bottom: 60px;
        .phoneandTipsWrap {
            position: relative;
            .tips {
                padding-left: 22px;
                font-size: 27px;
                color: #7c1919;
                position: absolute;
            }
        }
    }
`;
